home *** CD-ROM | disk | FTP | other *** search
- Path: news.interpath.net!usenet
- From: "Richard F. Albury" <richard.albury@virtus.com>
- Newsgroups: comp.lang.c++,comp.lang.pascal.delphi.misc
- Subject: Re: Calling all API experts !!
- Date: Tue, 19 Mar 1996 09:33:20 -0500
- Organization: Virtus Corporation
- Message-ID: <314EC5B0.7C0C@virtus.com>
- References: <DoIMG1.F9y@unx.sas.com>
- NNTP-Posting-Host: albury-win.virtus.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (WinNT; I)
-
- sdkkah@mvs.sas.com wrote:
- > I am trying to make an application with a tool which just recently allowed
- > calling Windows API's. The tool (The SAS System) itself is written in C++.
- > Some API's works OK, but there's one I cant figure out how to use right.
- > Its called GetProfileString. I need to access the [fonts] section of WIN.INI,
- > and get all entries and values. But I dont know the number of entries to
- > read, since this obviously varies. Is there some kind of trick that would
- > allow me to loop through untill the last entry is read, without having to
- > know the exact number of entries in each section ?
- >
- > Getting the font names is just getting me half the way. I also need to
- > know the point size and property (Bold,Italic etc..). Does anyone know
- > where I can get this information ?
- >
- > Finally, can anyone recommend any good documentations as to how
- > Windows API's are dealt with in general ?
-
- The following function will let you read all the keys for a section. Once you
- have the keys, you can easily get the values. As for documentation on the
- Windows API, the SDK manuals (also available as online help for most development
- systems) and "Programming Windows" by Charles Petzold (on the MSDN CD-ROM and
- recently updated for Windows 95) are your two best bets. Hope this helps.
-
- const DWORD INITIAL_BUFFER_SIZE = 512;
- const DWORD BUFFER_GROW_INCREMENT = 32;
-
- int // number of keys found in this section
- EnumerateKeys(
- LPCSTR sectionName) // section name, i.e., "fonts"
- {
- int nKeys = 0;
-
- DWORD dwChars = INITIAL_BUFFER_SIZE;
-
- LPSTR buffer = new char[dwChars];
-
- DWORD dwCharsRead = GetProfileString(sectionName,
- NULL,
- "",
- buffer,
- dwChars);
- while ( dwCharsRead >= (dwChars - 2) )
- {
- delete [] buffer;
- dwChars += BUFFER_GROW_INCREMENT;
- buffer = new char[dwChars];
- dwCharsRead = GetProfileString(sectionName,
- NULL,
- "",
- buffer,
- dwChars);
- }
-
- if ( dwCharsRead )
- {
- LPCSTR key = buffer;
- while ( *key )
- {
- #ifdef _DEBUG
- OutputDebugString(key);
- OutputDebugString("\r\n");
- #endif // _DEBUG
- ++nKeys;
- key += lstrlen(key) + 1;
- }
- }
-
- delete [] buffer;
-
- return nKeys;
- }
-